package com.xiu.travel.util;

import java.util.Random;
import java.util.regex.Pattern;

/**
 * @author lijie
 * @date 2023/6/21 11:53
 * @description PayCodeUtils
 */
public class PayCodeUtils
{
    private static final String REGEX = "^(35)\\d{16}$";
    private static final Pattern PATTERN = Pattern.compile(REGEX);

    public static String generate() {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();

        // 生成前两位数字
        int firstTwoDigits = 35;
        sb.append(firstTwoDigits);

        // 生成后面的 16 个数字
        for (int i = 0; i < 16; i++) {
            sb.append(random.nextInt(10));
        }

        // 检查是否符合正则表达式要求
        if (PATTERN.matcher(sb.toString()).matches()) {
            return sb.toString();
        }else{
            return generate();
        }
    }
}
